package com.task.web.controller.core;

import javax.annotation.Resource;

import com.task.core.vo.resp.IpFraudIDetailVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.task.common.annotation.Log;
import com.task.common.core.controller.BaseController;
import com.task.common.core.domain.AjaxResult;
import com.task.common.core.page.TableDataInfo;
import com.task.common.enums.BusinessType;
import com.task.common.utils.SecurityUtils;
import com.task.core.dto.request.IpFraudRequestDTO;
import com.task.core.service.CheckService;
import com.task.core.service.IpFraudService;

import io.swagger.annotations.Api;

/**
 * @author 迪迦.
 * @date 2024/11/4 14:31
 */
@Api("")
@RestController
@RequestMapping("/ipFraud")
public class IpFraudController extends BaseController {

  @Resource
  private IpFraudService ipFraudService;

  @Resource
  private CheckService checkService;


  @PreAuthorize("@ss.hasPermi('ipFraud:list')")
  @GetMapping("/getIpFraudByPage")
  public TableDataInfo getIpFraudByPage(IpFraudRequestDTO request) {
    startPage(request.getPageNum(), request.getPageSize());
    return getDataTable(ipFraudService.getIpFraudByPage(request));
  }


  @PreAuthorize("@ss.hasPermi('ipFraud:option')")
  @GetMapping("/getIpFraudForOption")
  public TableDataInfo getIpFraudForOption(IpFraudRequestDTO request) {
    return getDataTable(ipFraudService.getIpFraudForOption(request));
  }

  @Log(title = "IpFraud管理", businessType = BusinessType.INSERT)
  @PostMapping("/addIpFraud")
  public AjaxResult addIpFraud(@RequestBody IpFraudRequestDTO request) {
    request.setOperationBy(SecurityUtils.getLoginUser().getUserId());
    ipFraudService.addIpFraud(request);
    return success();
  }

  @Log(title = "IpFraud管理", businessType = BusinessType.UPDATE)
  @PutMapping("/modifyIpFraud")
  public AjaxResult modifyIpFraud(@RequestBody IpFraudRequestDTO request) {
    checkService.check("data_ip_fraud", request.getCode());
    request.setOperationBy(SecurityUtils.getLoginUser().getUserId());
    ipFraudService.modifyIpFraud(request);
    return success();
  }

  @Log(title = "IpFraud管理", businessType = BusinessType.DELETE)
  @DeleteMapping("/deleteIpFraud/{ipFraudCode}")
  public AjaxResult deleteIpFraud(@PathVariable String ipFraudCode) {
    checkService.check("data_ip_fraud", ipFraudCode);
    ipFraudService.deleteIpFraud(ipFraudCode, SecurityUtils.getLoginUser().getUserId());
    return success();
  }

  @GetMapping ("/getIpFraud/{ipFraud}")
  @PreAuthorize("@ss.hasPermi('system:ipFraud:edit')")
  public AjaxResult getIpFraudDetail(@PathVariable String ipFraud) {
    checkService.check("data_ip_fraud", ipFraud);
    IpFraudIDetailVo ipFraudIDetailVo= ipFraudService.getIpFraudDetail(ipFraud);
    return success(ipFraudIDetailVo);
  }



}
